{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}

<table id="table" lay-filter="table"></table>
<script type="text/html" id="switchTpl">
  <input type="checkbox" name="id" value="{{d.id}}" lay-skin="switch" lay-filter="button" lay-text="开|关" {{ d.val == 1 ? 'checked' : '' }}>
</script>

{/block}
{block name="script"}
<script>
layui.use('table', function(){
  var table = layui.table
  ,form = layui.form;
  table.render({
  elem: '#table'
  ,height: 'full-150'
  ,url: '/admin/system/buttonList/' //数据接口
  ,limit:20
  ,page: true //开启分页
  ,cols: [[ //表头
    {field:'discription', title: '参数名', width: 500}
    ,{field:'val', title:'开关', width:85, templet: '#switchTpl'}
    ]]
  }); 

    //监听性开关操作
  form.on('switch(button)', function(obj){
    var post_data = {
      id:this.value,
    };
    $.ajax({
            url:"{:url('admin/system/editButton')}",
            type:"POST",
            data:post_data,
            success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  $(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
    // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
  });
});
</script>
{/block}
